

export default {
    allShopSelect(state){
        const isAllSelect=state.isAllSelect;
        if(isAllSelect==false){
            state.isAllSelect=true;
            state.shopCart.forEach(function(item,index){
                item.isSelect=true;
                item.goodsItems.forEach(function(element,eleIndex){
                    element.isSelect=true;
                })
            })
        }else{
            state.isAllSelect=false;
            state.shopCart.forEach(function(item,index){
                item.isSelect=false;
                item.goodsItems.forEach(function(element,eleIndex){
                    element.isSelect=false;
                })
            })
        }
    },
    everyGoodsSelect(state,{cartIndex,goodsIndex}){
        const isSelect=state.shopCart[cartIndex].goodsItems[goodsIndex].isSelect;
        if(isSelect==false){
            state.shopCart[cartIndex].goodsItems[goodsIndex].isSelect=true;
        }else{
            state.shopCart[cartIndex].goodsItems[goodsIndex].isSelect=false;
        }
        const len=state.shopCart[cartIndex].goodsItems.length;
        var index=0;
        // console.log(len,goodsIndex,999);
        for(var i=0;i<len;i++){
            // console.log(state.shopCart[cartIndex].goodsItems[i].isSelect);
            if(state.shopCart[cartIndex].goodsItems[i].isSelect==true){
                index++;
                // console.log(index);
                if(index==len){
                state.shopCart[cartIndex].isSelect=true;                    
                }
                // state.shopCart[cartIndex].isSelect=true;
            }else{
                index--;
                state.shopCart[cartIndex].isSelect=false;                
            }
        }
    },
    everyShopSelect(state,{cartIndex,goodsIndex}){
        const isSelect=state.shopCart[cartIndex].isSelect;
        if(isSelect==false){
            state.shopCart[cartIndex].isSelect=true;
            state.shopCart[cartIndex].goodsItems.forEach(function(item,index){
                item.isSelect=true;
            })

        }else{
            state.shopCart[cartIndex].isSelect=false;
            state.shopCart[cartIndex].goodsItems.forEach(function(item,index){
                item.isSelect=false;
            })
        }
        const len=state.shopCart.length;
        // console.log(len);
        var i=0;
        for(var j=0;j<len;j++){
            if(state.shopCart[j].isSelect==true){
                i++;
                if(i==len){
                    state.isAllSelect=true;
                }
            }else{
                i--;
                state.isAllSelect=false;
            }
        }
    },

    // deleteShoping(state,{cartIndex,goodsIndex}){
    //     this.$confirm('确定要删除该商品吗？')
    // },
    add(state,{cartIndex,goodsIndex}){
        // const count=state.shopCart[cartIndex].goodsItems[goodsIndex].count;
        state.shopCart[cartIndex].goodsItems[goodsIndex].count++;
    },
    // minus(state,{cartIndex,goodsIndex}){
    //     const count=state.shopCart[cartIndex].goodsItems[goodsIndex].count;
    //     if(count<=1){
    //         state.shopCart[cartIndex].goodsItems[goodsIndex].count=1
    //     }else{
    //     state.shopCart[cartIndex].goodsItems[goodsIndex].count--;        
    //     }
    // }
}